<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="/WEB-INF/aitag.tld" prefix="ai"%>   
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="${ctx}/css_inc"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>营销总量管理设置</title>

</head>

<body>
	<div class="row">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<form class="form-horizontal m-t" id="dataForm">
					<div class="form-group">
						<label class="col-sm-3 control-label">限制类型：</label>
						<div class="col-sm-8">
						   <input id="limitId" name="limitId" type="hidden" value="${dayLimitCfg.limitId}" />
							<select id="type" name="type" class="form-control m-b" aria-required="true" aria-invalid="false" disabled="disabled" >
								<option value="DAY_LIMIT">每日营销总量</option>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">限制目标类型：</label>
						<div class="col-sm-8">
						 
							<ai:SelectStaticData codetype="DAY_LIMIT_CFG_TARGET_TYPE" id="targetType" name="targetType" disabled="${targetTypeDisabled}" selectClass="form-control m-b" defaultValue="" defaultText="请选择限制目标类型" selected="${dayLimitCfg.targetType}"></ai:SelectStaticData>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">限制目标：</label>
						<div class="col-sm-8">
							<input id="targetId" name="targetId" class=" form-control tree-select" type="hidden" value="${dayLimitCfg.targetId}">
							<input id="channelId" name="channelId" class=" form-control tree-select" 
							 
								<c:if test="${!empty dayLimitCfg && dayLimitCfg.targetType=='CHANNEL'}">
									disabled="disabled" attr-value="${dayLimitCfg.targetId}" value="${dayLimitCfg.targetName}"
								</c:if>
								<c:if test="${!empty dayLimitCfg && dayLimitCfg.targetType=='POINT'}">
									style="display:none"
								</c:if>
							>
							<input id="pointId" name="pointId" class=" form-control tree-select" 
								<c:choose> 
									<c:when test="${!empty dayLimitCfg && dayLimitCfg.targetType=='POINT'}">
										disabled="disabled" attr-value="${dayLimitCfg.targetId}" value="${dayLimitCfg.targetName}"
									</c:when>
	  								<c:otherwise>
	  									style="display:none"
	  								</c:otherwise>
  								</c:choose> 
							>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">限制值：</label>
						<div class="col-sm-8">
							<input id="limitValue" name="limitValue" class="form-control" type="number" value="${dayLimitCfg.limitValue}">
						</div>
					</div> 
				</form>
			</div>
		</div>
	</div>
	<jsp:include page="${ctx}/js_inc"></jsp:include>
	<script type="text/javascript">
 
	var channelTree;//下拉渠道tree
	var pointTree;//下拉触点tree
	
	
 
	
	$().ready(function() {
		$('#dataForm').validate({
			rules : { 
				targetType : 'required',  
				channelId : 'required', 
				pointId : 'required', 
				limitValue : 'required'
			},
			messages : { 
				targetType : validatorIcon + '不能为空',  
				channelId : validatorIcon + '不能为空', 
				pointId : validatorIcon + '不能为空', 
				limitValue : validatorIcon + '不能为空'
			}
		});
		
		$.post('${ctx}/contactmgn/point/getChannelTree', 
    			function (data) {
					if(data.success){
						channelTree = data.obj;  
				}}
    	); 
		$.post('${ctx}/contactmgn/point/getPointTree', 
    			function (data) {
			     	 if(data.success){
			    	  	pointTree = data.obj;  
				}}
    	);
	
		 
	});
	$('#targetType').change(function(){  
		var targetType=$('#targetType').val();
		$('#pointId').data('value','');
		$('#pointId').val(''); 
		
		$('#channelId').data('value','');
		$('#channelId').val(''); 
		$('#targetId').val(''); 
		if (targetType === 'CHANNEL') {
			$('#pointId').hide();
			$('#channelId').show();
		}
		if (targetType === 'POINT') {
			$('#channelId').hide();
			$('#pointId').show();
		}
	});
	
	
	$('#pointId').click(function(){
		if ($('#targetType').val() != '') {
			treeSelect(this,pointTree,true,true);
		}
		return false;
	});
	
	$('#channelId').click(function(){
		if ($('#targetType').val() != '') {
			treeSelect(this,channelTree,true);
		}
		return false;
	});
	
	
	function pointIdonClick(e, treeId, treeNode) { 
		var obj = $('#pointId');
  		obj.val(treeNode.name);  
		obj.data('value',treeNode.id); 
		$('#targetId').val(treeNode.id);  
	}
	
	function pointIdbeforeClick(treeId, treeNode, clickFlag){
 		var check = (treeNode && !treeNode.parent);
		if (!check) alert("只能选择触点...");
		return check; 
	}
	
	function channelIdonClick(e, treeId, treeNode) { 
  		var obj = $('#channelId');
  		obj.val(treeNode.name);  
		obj.data('value',treeNode.id);
		$('#targetId').val(treeNode.id);  
	}
	
	</script>
</body>

</html>
